#include "s-int.h"
#include "../TLoad/dns.h"
using namespace std;




int main()
{
    // encrypt MD5
    {
        unsigned char md5[]  = {0x9C, 0x50, 0x55, 0xEA, 0x53, 0x2E, 0x41, 0x6D, 0x7C, 0xA0, 0xF5, 0xCD, 0x87, 0xEC, 0x33, 0xF2};
        unsigned char sealed_md5[16] = {0};
		ShiningloreCryptoCache::getRijndaelEncrypter()->encrypt(md5, 16, sealed_md5);

        cout << "sealed_md5 = {" << hex;
        for(int i=0; i<16; i++)
		    cout << (int)sealed_md5[i];

        cout << dec << "};" << endl;

        // 817769B47C7D2AF7AEC5C03E23495AAC
        // 0x81, 0x77, 0x69, 0xB4, 0x7C, 0x7D, 0x2A, 0xF7, 0xAE, 0xC5, 0xC0, 0x3E, 0x23, 0x49, 0x5A, 0xAC
    }

	// CFileVersion test
	{
		auto t509 = ShiningloreVersionCache::getT509Ver();
		cout << "T509->" << t509->ToStringA() << endl;

		auto x509 = ShiningloreVersionCache::getX509Ver();
		cout << "X509->" << x509->ToStringA() << endl;
	}

	// Crypto test
	{
		char test[] = "Hello Miles and Molly!#########";
		test[16] = '\0';
		char pt[17], ct[16];

		cout << test << endl;

		ShiningloreCryptoCache::getRijndaelEncrypter()->encrypt((unsigned char*)test, 16, (unsigned char*)ct);
		cout << hex;
		for(int i=0; i<16; i++)
		{
			cout << (short)(unsigned char)ct[i] << " ";
		}
		cout << endl << dec;

		ShiningloreCryptoCache::getRijndaelDecrypter()->decrypt((unsigned char*)ct, 16, (unsigned char*)pt);
		pt[16] = '\0';
		cout << pt << endl;
	}

	// SODA
	{
		// extract SODA
		bool hr = soda::extract(L"dxyl.bin");
		cout << "extract soda, result=" << hr << endl;

		/*
		unsigned char a[2], b[50], c[50], option[5];
		int x=2, y=50, z=50, ol=5;
		
		for(int i=0; i<2; i++)
			a[i] = rand()%20;

		

		int hr = LzmaCompress(b, (size_t*)&y, a, x, option, (size_t*)&ol,
			-1,
			0,
			-1,
			-1,
			-1,
			-1,
			-1);
		if(hr != SZ_OK)
			cout << "fail" <<endl;

		
		hr = LzmaUncompress(c, (size_t*)&z, b, (size_t*)&y, option, ol);
		if(hr != SZ_OK)
			cout << "fail" <<endl;
*/
	}

	// DNS resolve
	{
		auto ip = dns::instance()->resolve("shtsol.vicp.cc");
		cout << "dns::resolve('shtsol.vicp.cc') = " << ip << endl;
	}

	cout << "ok" << endl;
	return 0;
}